<!DOCTYPE html>
<html lang="en">

<head>
    <!-- <meta http-equiv="refresh" content="1"> -->
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        .time-item {
            width: 450px;
            height: 45px;
            margin: 0 auto;
        }

        .time-item strong {
            background: orange;
            color: #fff;
            line-height: 49px;
            font-size: 36px;
            font-family: Arial;
            padding: 0 10px;
            margin-right: 10px;
            border-radius: 5px;
            box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
        }

        .time-item>span {
            float: left;
            line-height: 49px;
            color: orange;
            font-size: 32px;
            margin: 0 10px;
            font-family: Arial, Helvetica, sans-serif;
        }

        .title {
            width: 260px;
            height: 50px;
            margin: 200px auto 50px auto;
        }
    </style>

</head>

<body>
    <h1 class="title">距离光棍节，还有</h1>

    <div class="time-item">
        <span><span id="day">1</span>天</span>
        <strong><span id="hour">2</span>时</strong>
        <strong><span id="minute">3</span>分</strong>
        <strong><span id="second">4</span>秒</strong>
    </div>
    <script>
        function mytime() {

            var gun = new Date('2023-11-11 00:00:00'); //目标时间对象
            var current = new Date(); // 当前时间的时间对象

            var target = gun.getTime();//获取目标时间对象的时间戳 
            var newtime = current.getTime();//获取当前时间对象的时间戳 
            // js获取的时间戳是毫秒  13位

            var res = parseInt((target - newtime) / 1000); // 将毫秒转成秒
            console.log(res);
            // 这么多秒 有多少个 天(3600*24)  小时 3600  分钟 60  秒 
            var day = parseInt(res / (3600 * 24));
            var hour = parseInt(res % (3600 * 24) / 3600);
            var minute = parseInt(res % 3600 / 60);
            var second = res % 60;


            document.getElementById('day').innerHTML = day;
            document.getElementById('hour').innerHTML = hour;
            document.getElementById('minute').innerHTML = minute;
            document.getElementById('second').innerHTML = second
        }
        var res = setInterval(mytime, 1000);

    </script>


</body>

</html>